﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using QuanLyKhachSan.DataAccess;
using QuanLyKhachSan.BusinessObject;
using QuanLyKhachSan.BusinessLogic;
namespace QuanLyKhachSan
{
    public partial class frmDichVu : Form
    {
        private DichVuBL dvBL = new DichVuBL();
        private DichVuBO dvBO = new DichVuBO();
        string dichvu = null;
        public frmDichVu()
        {
            InitializeComponent();
        }

        private void frmDichVu_Load(object sender, EventArgs e)
        {
            dgvwDichVu.DataSource = dvBL.LayDSDichVu();

        }

        private void dgvwDichVu_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            int dong = e.RowIndex;
         //   dvBO. = dgvwDichVu.Rows[dong].Cells["STT"].Value.ToString();
            dvBO.MaDichVu = dgvwDichVu.Rows[dong].Cells["MaDichVu"].Value.ToString();
            dvBO.TenDichVu = dgvwDichVu.Rows[dong].Cells["TenDichVu"].Value.ToString();
            dvBO.DonGia = int.Parse(dgvwDichVu.Rows[dong].Cells["DonGia"].Value.ToString());
        }



        private void LayDuLieu(DichVuBO DV)
        {
            this.dichvu = DV.MaDichVu;
            if (!dichvu.Equals(""))
            {
                dgvwDichVu.DataSource = dvBL.LayDSDichVu();
            }
        }



        private void txtTimKiem_KeyUp(object sender, KeyEventArgs e)
        {

        }

        private void btnThem_Click_1(object sender, EventArgs e)
        {
            frmAddDichVu fadv = new frmAddDichVu();
            fadv.NextID();
            fadv.DuLieu = new frmAddDichVu.DuLieuTruyenVe(LayDuLieu);
            fadv.Show();
        }

        private void btnSua_Click_1(object sender, EventArgs e)
        {
            frmAddDichVu fadv = new frmAddDichVu();
            fadv.Load_Edit(dvBO);
            fadv.DuLieu = new frmAddDichVu.DuLieuTruyenVe(LayDuLieu);
            fadv.Show();
        }

        private void btnXoa_Click_1(object sender, EventArgs e)
        {
            if (dvBO.MaDichVu == "")
                MessageBox.Show("Chọn mã nhân viên", "Chương trình thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
            else
            {
                if (MessageBox.Show("Bạn có chắc muốn xóa hay không", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                {
                    dvBL.Delete(dvBO.MaDichVu);
                    frmDichVu_Load(sender, e);
                }
            }
        }

        private void btnThoat_Click_1(object sender, EventArgs e)
        {
            bool kq = (MessageBox.Show("Bạn có chắc chắn muốn thoát không ?", "Thông Báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes);
            if (kq == true)
            {
                this.Close();
            }
        }

        private void txtTimKiem_KeyUp_1(object sender, KeyEventArgs e)
        {
            dgvwDichVu.DataSource = dvBL.TimKiemDichVu(txtTimKiem.Text);
        }


    }
}
